/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import static persistencia.DBManagerPacientes.conexion;
import modelo.Pacientes;
import modelo.MetodosPacientes;

/**
 * Panel en el que Rellenamos campo por campo para poder crear el modelo;
 * @author Kevin
 */
public class JPAñadirPaciente extends javax.swing.JPanel {

    
    /**
     * Creates new form JPModeloCreacion
     */
    public JPAñadirPaciente() throws SQLException, ClassNotFoundException {
        initComponents();

        
            jbAñadirPaciente.addActionListener(new ActionListener() {
                
            @Override
            public void actionPerformed(ActionEvent e) {
                
              String nombrePaciente = jTextField_nombrePaciente.getText();
                Pacientes nPacientes = new Pacientes(nombrePaciente);
              String dniPaciente = jTextField_dniPaciente.getText();
                Pacientes dPacientes = new Pacientes(dniPaciente);
              String direccionPaciente = jTextField_Direccion.getText();
                Pacientes dirPacientes = new Pacientes(direccionPaciente);
              String poblacionPaciente = jTextField_Poblacion.getText();
                Pacientes pPacientes = new Pacientes(poblacionPaciente);
              String PrimerApellidoPaciente = jTextField_PrimerApellido.getText();
                Pacientes pApellidoPacientes = new Pacientes(PrimerApellidoPaciente);
              String SegundoApellidoPaciente = jTextField_SegundoApellido.getText();
                Pacientes sApellidoPacientes = new Pacientes(SegundoApellidoPaciente);
              int codPaciente = Integer.parseInt(jTextField_codPaciente.getText());
                Pacientes cPaciente = new Pacientes (Integer.toString(codPaciente));
              int codPostal = Integer.parseInt(jTextField_codPostal.getText());
                Pacientes cPostalPaciente = new Pacientes (Integer.toString(codPostal));
              
               MetodosPacientes mtp = null;
                try {
                    mtp = new MetodosPacientes();
                    mtp.addPaciente(cPaciente,dPacientes, dPacientes,pApellidoPacientes, sApellidoPacientes,dirPacientes,pPacientes, cPostalPaciente);
                    System.out.println ("EL PACIENTE HA SIDO CREADO");
                } catch (SQLException ex) {
                    System.err.println ("SQLEXCEPTION.");
                    ex.printStackTrace();
                }
              
              
               }
        });
        
    }
   

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jbAñadirPaciente = new javax.swing.JButton();
        jLabel_Titulo = new javax.swing.JLabel();
        jLabel_codPaciente = new javax.swing.JLabel();
        jLabel_direccionPaciente = new javax.swing.JLabel();
        jLabel_DNI = new javax.swing.JLabel();
        jLabel_codPostal = new javax.swing.JLabel();
        jLabel_PoblacionPaciente = new javax.swing.JLabel();
        jLabel_SegundoApellido = new javax.swing.JLabel();
        jLabel_PrimerApellido = new javax.swing.JLabel();
        jLabel_Nombre = new javax.swing.JLabel();
        jTextField_dniPaciente = new javax.swing.JTextField();
        jTextField_nombrePaciente = new javax.swing.JTextField();
        jTextField_codPaciente = new javax.swing.JTextField();
        jTextField_codPostal = new javax.swing.JTextField();
        jTextField_PrimerApellido = new javax.swing.JTextField();
        jTextField_SegundoApellido = new javax.swing.JTextField();
        jTextField_Poblacion = new javax.swing.JTextField();
        jTextField_Direccion = new javax.swing.JTextField();

        setLayout(new java.awt.GridBagLayout());

        jbAñadirPaciente.setText("Añadir Paciente");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.gridwidth = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(27, 95, 20, 0);
        add(jbAñadirPaciente, gridBagConstraints);

        jLabel_Titulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel_Titulo.setText("Añadir Paciente");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 18;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 50, 0, 0);
        add(jLabel_Titulo, gridBagConstraints);

        jLabel_codPaciente.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_codPaciente.setText("Código Paciente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(17, 21, 0, 0);
        add(jLabel_codPaciente, gridBagConstraints);

        jLabel_direccionPaciente.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_direccionPaciente.setText("Dirección:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 21, 0, 0);
        add(jLabel_direccionPaciente, gridBagConstraints);

        jLabel_DNI.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_DNI.setText("DNI del paciente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 21, 0, 0);
        add(jLabel_DNI, gridBagConstraints);

        jLabel_codPostal.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_codPostal.setText("Código Postal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 21, 0, 0);
        add(jLabel_codPostal, gridBagConstraints);

        jLabel_PoblacionPaciente.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_PoblacionPaciente.setText("Población:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 21, 0, 0);
        add(jLabel_PoblacionPaciente, gridBagConstraints);

        jLabel_SegundoApellido.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_SegundoApellido.setText("Segundo Apellido:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 17;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 28;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(20, 18, 0, 0);
        add(jLabel_SegundoApellido, gridBagConstraints);

        jLabel_PrimerApellido.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_PrimerApellido.setText("Primer Apellido:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 17;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(17, 18, 0, 0);
        add(jLabel_PrimerApellido, gridBagConstraints);

        jLabel_Nombre.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_Nombre.setText("Nombre:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 17;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 18, 0, 0);
        add(jLabel_Nombre, gridBagConstraints);

        jTextField_dniPaciente.setText("jTextField1");
        jTextField_dniPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_dniPacienteActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 96;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(16, 9, 0, 0);
        add(jTextField_dniPaciente, gridBagConstraints);

        jTextField_nombrePaciente.setText("jTextField2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 18;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 38;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 186;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(16, 4, 0, 36);
        add(jTextField_nombrePaciente, gridBagConstraints);

        jTextField_codPaciente.setText("jTextField3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 96;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(15, 9, 0, 0);
        add(jTextField_codPaciente, gridBagConstraints);

        jTextField_codPostal.setText("jTextField4");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 8;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 110;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 10, 0, 0);
        add(jTextField_codPostal, gridBagConstraints);

        jTextField_PrimerApellido.setText("jTextField5");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 27;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 29;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 141;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(15, 4, 0, 36);
        add(jTextField_PrimerApellido, gridBagConstraints);

        jTextField_SegundoApellido.setText("jTextField6");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 55;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 125;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 4, 0, 36);
        add(jTextField_SegundoApellido, gridBagConstraints);

        jTextField_Poblacion.setText("jTextField7");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 54;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 401;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 10, 0, 36);
        add(jTextField_Poblacion, gridBagConstraints);

        jTextField_Direccion.setText("jTextField8");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 54;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 401;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 10, 0, 36);
        add(jTextField_Direccion, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField_dniPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_dniPacienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_dniPacienteActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel_DNI;
    private javax.swing.JLabel jLabel_Nombre;
    private javax.swing.JLabel jLabel_PoblacionPaciente;
    private javax.swing.JLabel jLabel_PrimerApellido;
    private javax.swing.JLabel jLabel_SegundoApellido;
    private javax.swing.JLabel jLabel_Titulo;
    private javax.swing.JLabel jLabel_codPaciente;
    private javax.swing.JLabel jLabel_codPostal;
    private javax.swing.JLabel jLabel_direccionPaciente;
    private javax.swing.JTextField jTextField_Direccion;
    private javax.swing.JTextField jTextField_Poblacion;
    private javax.swing.JTextField jTextField_PrimerApellido;
    private javax.swing.JTextField jTextField_SegundoApellido;
    private javax.swing.JTextField jTextField_codPaciente;
    private javax.swing.JTextField jTextField_codPostal;
    private javax.swing.JTextField jTextField_dniPaciente;
    private javax.swing.JTextField jTextField_nombrePaciente;
    private javax.swing.JButton jbAñadirPaciente;
    // End of variables declaration//GEN-END:variables
}
